package com.hsteach.web.controller.meeting;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.exception.ServiceException;
import com.hsteach.enums.ApplyTypeEnum;
import com.hsteach.service.meeting.MeetingApplyService;
import com.hsteach.web.controller.buildingApply.dto.*;
import com.hsteach.web.controller.meeting.dto.AddMeetingApplyDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 会议申请Controller
 *
 * @author fanxquer
 * @date 2023-08-25
 */
@Api(value = "会议申请", tags = "会议申请")
@RestController
@RequestMapping("/meeting")
public class MeetingApplyController extends BaseController
{
    @Autowired
    private MeetingApplyService meetingApplyService;

    /**
     * 查询会议申请列表
     */
    @ApiOperation("查询会议申请列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ListBuildingApplyDto dto)
    {
        return meetingApplyService.listMine(dto, ApplyTypeEnum.MEETING);
    }

    /**
     * 查询会议审核列表
     */
    @ApiOperation("查询会议审核列表")
    @PostMapping("/review/list")
    public TableDataInfo listReview(@RequestBody ListReviewDto dto)
    {
        if (ObjectUtils.isEmpty(dto.getPageSize()) || ObjectUtils.isEmpty(dto.getPageNum())) {
            throw new ServiceException("分页参数异常",-1);
        }
        //如果状态参数为空，则赋值任意值，表示查询全部
        if (dto.getApplyStatus() == null) {
            dto.setApplyStatus(-999);
        }
        return meetingApplyService.listReview(dto, ApplyTypeEnum.MEETING);
    }

    /**
     * 会议审核
     */
    @ApiOperation("会议审核")
    @PutMapping("/review")
    public AjaxResult review(@RequestBody ReviewDto dto)
    {
        return toAjax(meetingApplyService.review(dto));
    }

    /**
     * 查询会议时间占用
     */
    @ApiOperation("查询会议时间占用")
    @PostMapping("/holdingTime")
    public TableDataInfo listHoldingTime(@RequestBody ListHoldingTimeDto dto)
    {
        return getDataTable(meetingApplyService.listHoldingTime(dto));
    }

    /**
     * 查询课表时间占用
     */
    @ApiOperation("查询课表时间占用")
    @PostMapping("/timetable")
    public TableDataInfo listTimetable(@RequestBody ListTimetableDto dto)
    {
        return getDataTable(meetingApplyService.listTimetable(dto));
    }

    /**
     * 查询建筑下的会议场所列表
     */
    @ApiOperation("查询建筑下的会议场所列表(包含当天时间占用情况)")
    @GetMapping("/rooms")
    public TableDataInfo listRooms(ListRoomsDto dto)
    {
        return getDataTable(meetingApplyService.listRooms(dto.getBuildingId(), dto.getType(), dto.getSearchDate()));
    }

    /**
     * 获取会议申请详细信息
     */
    @ApiOperation("获取会议申请详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingApplyService.getInfo(id));
    }

    /**
     * 新增会议申请
     */
    @ApiOperation("新增会议申请")
    @PostMapping
    public AjaxResult add(@RequestBody AddMeetingApplyDto dto)
    {
        return toAjax(meetingApplyService.buildingApply(dto, ApplyTypeEnum.MEETING));
    }

    /**
     * 取消会议申请
     */
    @ApiOperation("取消会议申请")
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelApplyDto dto)
    {
        return toAjax(meetingApplyService.cancelApply(dto));
    }
}
